<?php

namespace Common\Model;

use Think\Model;
use Org\Nx\Page;

class TradeDealModel extends Model {
    public static function newSelf()
    {
        return new self();
    }
    public function findOneById($id)
    {
        return $this->where(['id'=>$id])->find();
    }
	public function pagingList($where=array(),$map=array(),$num=10,$order='id desc')
	{
		$count      = $this->where($map)->where($where)->count();
		$Page       = new Page($count,$num);
		foreach($map as $key=>$val) {
		    $Page->parameter[$key]   =   urlencode($val);
		}
		$type=FinanceTypeModel::newSelf()->getInfo();
		$model=UserModel::newSelf();
		$currency=CurrencyModel::newSelf()->getInfo();
		$show = $Page->show();
		$list = $this->where($map)->where($where)->order($order)->limit($Page->firstRow.','.$Page->listRows)->select();
		foreach ($list as $k=>$v)
		{
		    $list[$k]['finance_type']=$type[$v['type']];
		    $list[$k]['from_user']=$model->findUserByUserId($v['from_id']);
		    $list[$k]['user']=$model->findUserByUserId($v['user_id']);
		    $list[$k]['currency']=$currency[$v['currency_id']];
		}
		return array('page'=>$show,'content'=>$list);
	}
}